import { createRouter, createWebHashHistory } from "vue-router";
import Home from "../views/Home.vue";

const routes = [
  {
    path: "/",
    redirect: "/dashboard",
  },
  {
    path: "/",
    name: "Home",
    component: Home,
    children: [
      {
        path: "/dashboard",
        name: "dashboard",
        meta: {
          title: "系统首页",
        },
        component: () => import("../views/dashboard/Dashboard.vue"),
      },
      {
        path: "/userInfo",
        name: "userInfo",
        meta: {
          title: "用户信息",
        },
        component: () => import("../views/user/UserInfo.vue"),
      },
      {
        path: "/userAdd",
        name: "userAdd",
        meta: {
          title: "用户添加",
        },
        component: () => import("../views/user/UserAdd"),
      },
      {
        path: "/yingpinInfo",
        name: "yingpinInfo",
        meta: {
          title: "应聘信息",
        },
        component: () => import("../views/yingpin/YingPinInfo"),
      },
      {
        path: "/yingpinAdd",
        name: "yingpinAdd",
        meta: {
          title: "添加应聘",
        },
        component: () => import("../views/yingpin/YingPinAdd"),
      },
      {
        path: "/jzxxInfo",
        name: "jzxxInfo",
        meta: {
          title: "兼职信息",
        },
        component: () => import("../views/jzxx/JzxxInfo"),
      },
      {
        path: "/jzxxAdd",
        name: "jzxxAdd",
        meta: {
          title: "添加兼职",
        },
        component: () => import("../views/jzxx/JzxxAdd"),
      },
      {
        path: "/commentInfo",
        name: "commentInfo",
        meta: {
          title: "评论信息",
        },
        component: () => import("../views/comment/CommentInfo"),
      },
      {
        path: "/commentAdd",
        name: "commentAdd",
        meta: {
          title: "添加评论",
        },
        component: () => import("../views/comment/CommentAdd"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () =>
      import(/* webpackChunkName: "login" */ "../views/login/Login.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
//引入全局路由守卫
router.beforeEach((to, from) => {
  if (to.path !== "/login") {
    if (!window.localStorage.getItem("userInfo")) {
      return {
        path: "/login",
      };
    }
  }
});
export default router;
